<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of model_attribute
 *
 * @author b4by
 */
class model_attribute extends MY_Model{
	var $table = 'attribute';
	
	public function get_list($lang, $input = array()){
		if(!isset($input['select']))
			$input['select'] = 'id,p_id,name,value_type,compare_type,unit,validation,index';
		
		$input['where']['lang_id'] = $lang;
		
		$this->get_list_set_input($input);
		
		$this->db->from('attribute a');
		$this->db->join('attribute_info i','a.id = i.attrib_id');
		
		
		$query = $this->db->get();
		return $query->result();
	}
	
	public function get_list_hash($lang, $input = array()){
		$result = $this->get_list($lang, $input);
        $hash = array();
        foreach($result as $id => $obj)
            $hash[$obj->{$this->primary_key}] = $obj;
            
        return $hash;
	}
	public function get_info($id, $field = '')
	{
		$data = parent::get_info($id,$field);
		if($data===FALSE) return FALSE;
		$this->load->model('model_attribute_info');
		
		$info = $this->model_attribute_info->get_list(array(
			'where'	=> array('attrib_id'	=> $data->id),
			'order'	=> array('lang_id','asc')
		));
		foreach($info as $row)
			$data->info[$row->lang_id] = $row;
		
		return $data;
	}
}

?>
